﻿using Infrastructures;
using IRepository;
using Models;
using Newtonsoft.Json.Linq;
using Spring.Data.Common;
using Spring.Data.Generic;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RepositoryMySQL
{
    public class UtilRepository : IUtilRepository
    {
        #region School
        private string baseSchool = "select SchoolNO,SchoolName,StudentSize,ProvinceNO,CityNO,CountyNO,Address from School";
        public School CreateSchool(School obj)
        {
            string strIns = @"insert into School(SchoolName,StudentSize,ProvinceNO,CityNO,CountyNO,Address) values(@SchoolName,@StudentSize,@ProvinceNO,@CityNO,@CountyNO,@Address);SELECT LAST_INSERT_ID() as id";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("SchoolNO", DbType.Int32).Value = obj.SchoolNO;
            p.Add("SchoolName", DbType.String).Value = obj.SchoolName;
            p.Add("StudentSize", DbType.Int32).Value = obj.StudentSize;
            p.Add("ProvinceNO", DbType.Int32).Value = obj.ProvinceNO;
            p.Add("CityNO", DbType.Int32).Value = obj.CityNO;
            p.Add("CountyNO", DbType.Int32).Value = obj.CountyNO;
            p.Add("Address", DbType.String).Value = obj.Address;

            int num = Int32.Parse(DBHelper.TemplateMySQL.ExecuteScalar(CommandType.Text, strIns, p).ToString());
            obj.SchoolNO = num;
            return obj;
        }
        public void UpdateSchool(School obj)
        {
            string strUpdate = @"update School set SchoolName=@SchoolName,StudentSize=@StudentSize,ProvinceNO=@ProvinceNO,CityNO=@CityNO,CountyNO=@CountyNO,Address=@Address where SchoolNO=@SchoolNO";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("SchoolNO", DbType.Int32).Value = obj.SchoolNO;
            p.Add("SchoolName", DbType.String).Value = obj.SchoolName;
            p.Add("StudentSize", DbType.Int32).Value = obj.StudentSize;
            p.Add("ProvinceNO", DbType.Int32).Value = obj.ProvinceNO;
            p.Add("CityNO", DbType.Int32).Value = obj.CityNO;
            p.Add("CountyNO", DbType.Int32).Value = obj.CountyNO;
            p.Add("Address", DbType.String).Value = obj.Address;

            DBHelper.TemplateMySQL.ExecuteNonQuery(CommandType.Text, strUpdate, p);
        }
        public School GetSchool(int schoolno)
        {
            string strSel = baseSchool + " where SchoolNO=@SchoolNO";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();
            p.Add("SchoolNO", DbType.Int32).Value = schoolno;

            IList<School> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<School>(MapSchool), p);
            return lst.Count == 0 ? null : lst[0];
        }
        public IList<School> ListSchool()
        {
            string strSel = baseSchool;

            IList<School> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<School>(MapSchool));

            return lst;
        }

        #endregion

        #region Money
        private string baseMoney = "select RoleNO,Fun,CountMoney,Balance from Money";
        public Money CreateMoney(Money obj)
        {
            string strIns = @"insert into Money(RoleNO,Fun,CountMoney,Balance) values(@RoleNO,@Fun,@CountMoney,@Balance);";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("RoleNO", DbType.Int32).Value = obj.RoleNO;
            p.Add("Fun", DbType.String).Value = obj.Fun;
            p.Add("CountMoney", DbType.Double).Value = obj.CountMoney;
            p.Add("Balance", DbType.Double).Value = obj.Balance;

            DBHelper.TemplateMySQL.ExecuteNonQuery(CommandType.Text, strIns, p);
            return obj;
        }
        public void UpdateMoney(Money obj)
        {
            string strUpdate = @"update Money set RoleNO=@RoleNO,Fun=@Fun,CountMoney=@CountMoney,Balance=@Balance where 1=1 ";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("RoleNO", DbType.Int32).Value = obj.RoleNO;
            p.Add("Fun", DbType.String).Value = obj.Fun;
            p.Add("CountMoney", DbType.Double).Value = obj.CountMoney;
            p.Add("Balance", DbType.Double).Value = obj.Balance;

            DBHelper.TemplateMySQL.ExecuteNonQuery(CommandType.Text, strUpdate, p);
        }

        public IList<Money> ListMoney()
        {
            string strSel = baseMoney;

            IList<Money> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<Money>(MapMoney));

            return lst;
        }

        #endregion

        #region MoneyLog
        private string baseMoneyLog = "select ID,Type,ValueFrom,ValueTo,Amount,Status,CreateTime,UpdateTime from MoneyLog";
        public MoneyLog CreateMoneyLog(MoneyLog obj)
        {
            string strIns = @"insert into MoneyLog(ID,Type,ValueFrom,ValueTo,Amount,Status,CreateTime,UpdateTime) values(@ID,@Type,@ValueFrom,@ValueTo,@Amount,@Status,@CreateTime,@UpdateTime);";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("ID", DbType.String).Value = obj.ID;
            p.Add("Type", DbType.String).Value = obj.Type;
            p.Add("ValueFrom", DbType.String).Value = obj.ValueFrom;
            p.Add("ValueTo", DbType.String).Value = obj.ValueTo;
            p.Add("Amount", DbType.Double).Value = obj.Amount;
            p.Add("Status", DbType.String).Value = obj.Status;
            p.Add("CreateTime", DbType.DateTime).Value = obj.CreateTime;
            p.Add("UpdateTime", DbType.DateTime).Value = obj.UpdateTime;

            DBHelper.TemplateMySQL.ExecuteNonQuery(CommandType.Text, strIns, p);
            return obj;
        }
        public void UpdateMoneyLog(MoneyLog obj)
        {
            string strUpdate = @"update MoneyLog set ID=@ID,Type=@Type,ValueFrom=@ValueFrom,ValueTo=@ValueTo,Amount=@Amount,Status=@Status,CreateTime=@CreateTime,UpdateTime=@UpdateTime where 1=1 ";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("ID", DbType.String).Value = obj.ID;
            p.Add("Type", DbType.String).Value = obj.Type;
            p.Add("ValueFrom", DbType.String).Value = obj.ValueFrom;
            p.Add("ValueTo", DbType.String).Value = obj.ValueTo;
            p.Add("Amount", DbType.Double).Value = obj.Amount;
            p.Add("Status", DbType.String).Value = obj.Status;
            p.Add("CreateTime", DbType.DateTime).Value = obj.CreateTime;
            p.Add("UpdateTime", DbType.DateTime).Value = obj.UpdateTime;

            DBHelper.TemplateMySQL.ExecuteNonQuery(CommandType.Text, strUpdate, p);
        }

        public IList<MoneyLog> ListMoneyLog()
        {
            string strSel = baseMoneyLog;

            IList<MoneyLog> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<MoneyLog>(MapMoneyLog));

            return lst;
        }


        #endregion

        #region eventlog
        private string baseEventLog = "select ID,InstanceID,EventID,ActionType,ActionObject,ActionTime,Operator,Remark from EventLog";
        public EventLog CreateEventLog(EventLog obj)
        {
            string strIns = @"insert into EventLog(InstanceID,EventID,ActionType,ActionObject,ActionTime,Operator,Remark) values(@InstanceID,@EventID,@ActionType,@ActionObject,@ActionTime,@Operator,@Remark);SELECT LAST_INSERT_ID() as id";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("ID", DbType.Int32).Value = obj.ID;
            p.Add("InstanceID", DbType.String).Value = obj.InstanceID;
            p.Add("EventID", DbType.String).Value = obj.EventID;
            p.Add("ActionType", DbType.String).Value = obj.ActionType;
            p.Add("ActionObject", DbType.String).Value = obj.ActionObject;
            p.Add("ActionTime", DbType.DateTime).Value = obj.ActionTime;
            p.Add("Operator", DbType.String).Value = obj.Operator;

            int max = Convert.ToInt32(SystemConfig.Get("MaxLogLength"));
            if (obj.Remark.Length > max)
                obj.Remark = obj.Remark.Substring(0, max);

            p.Add("Remark", DbType.String).Value = obj.Remark;

            int num = Int32.Parse(DBHelper.TemplateMySQL.ExecuteScalar(CommandType.Text, strIns, p).ToString());
            obj.ID = num;
            return obj;
        }
        public void UpdateEventLog(EventLog obj)
        {
            string strUpdate = @"update EventLog set InstanceID=@InstanceID,EventID=@EventID,ActionType=@ActionType,ActionObject=@ActionObject,ActionTime=@ActionTime,Operator=@Operator,Remark=@Remark where ID=@ID";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("ID", DbType.Int32).Value = obj.ID;
            p.Add("InstanceID", DbType.String).Value = obj.InstanceID;
            p.Add("EventID", DbType.String).Value = obj.EventID;
            p.Add("ActionType", DbType.String).Value = obj.ActionType;
            p.Add("ActionObject", DbType.String).Value = obj.ActionObject;
            p.Add("ActionTime", DbType.DateTime).Value = obj.ActionTime;
            p.Add("Operator", DbType.String).Value = obj.Operator;
            p.Add("Remark", DbType.String).Value = obj.Remark;

            DBHelper.TemplateMySQL.ExecuteNonQuery(CommandType.Text, strUpdate, p);
        }
        public EventLog GetEventLog(int id)
        {
            string strSel = baseEventLog + " where ID=@ID";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();
            p.Add("ID", DbType.Int32).Value = id;


            IList<EventLog> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<EventLog>(MapEventLog), p);
            return lst.Count == 0 ? null : lst[0];
        }
        public IList<EventLog> ListEventLog()
        {
            string strSel = baseEventLog;

            IList<EventLog> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<EventLog>(MapEventLog));

            return lst;
        }
 

        #endregion

        #region Area
        private string baseArea = "select Code,Name,Fun,Parent from Area";
        public Area CreateArea(Area obj)
        {
            string strIns = @"insert into Area(Name,Fun,Parent) values(@Name,@Fun,@Parent);SELECT LAST_INSERT_ID() as id";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("Code", DbType.Int32).Value = obj.Code;
            p.Add("Name", DbType.String).Value = obj.Name;
            p.Add("Fun", DbType.String).Value = obj.Fun;
            p.Add("Parent", DbType.Int32).Value = obj.Parent;

            int num = Int32.Parse(DBHelper.TemplateMySQL.ExecuteScalar(CommandType.Text, strIns, p).ToString());
            obj.Code = num;
            return obj;
        }
        public void UpdateArea(Area obj)
        {
            string strUpdate = @"update Area set Name=@Name,Fun=@Fun,Parent=@Parent where Code=@Code";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("Code", DbType.Int32).Value = obj.Code;
            p.Add("Name", DbType.String).Value = obj.Name;
            p.Add("Fun", DbType.String).Value = obj.Fun;
            p.Add("Parent", DbType.Int32).Value = obj.Parent;

            DBHelper.TemplateMySQL.ExecuteNonQuery(CommandType.Text, strUpdate, p);
        }
        public Area GetArea(int code)
        {
            string strSel = baseArea + " where Code=@Code";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();
            p.Add("Code", DbType.Int32).Value = code;


            IList<Area> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<Area>(MapArea), p);
            return lst.Count == 0 ? null : lst[0];
        }
        public IList<Area> ListArea()
        {
            string strSel = baseArea;

            IList<Area> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<Area>(MapArea));

            return lst;
        }

        #endregion

        #region baseData

        private string baseBaseData = "select RuleNO,Fun,Status,ValueFrom,ValueTo,Level,Version,Description,ParentNo,DisplayOrder from BaseData";
        public BaseData CreateBaseData(BaseData obj)
        {
            string strIns = @"insert into BaseData(Fun,Status,ValueFrom,ValueTo,Level,Version,Description,ParentNo,DisplayOrder) values(@Fun,@Status,@ValueFrom,@ValueTo,@Level,@Version,@Description,@ParentNo,@DisplayOrder);SELECT LAST_INSERT_ID() as id";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("RuleNO", DbType.Int32).Value = obj.RuleNO;
            p.Add("Fun", DbType.String).Value = obj.Fun;
            p.Add("Status", DbType.String).Value = obj.Status;
            p.Add("ValueFrom", DbType.String).Value = obj.ValueFrom;
            p.Add("ValueTo", DbType.String).Value = obj.ValueTo;
            p.Add("Level", DbType.String).Value = obj.Level;
            p.Add("Version", DbType.Int32).Value = obj.Version;
            p.Add("Description", DbType.String).Value = obj.Description;
            p.Add("ParentNo", DbType.Int32).Value = obj.ParentNo;
            p.Add("DisplayOrder", DbType.Int32).Value = obj.DisplayOrder;

            int num = Int32.Parse(DBHelper.TemplateMySQL.ExecuteScalar(CommandType.Text, strIns, p).ToString());
            obj.RuleNO = num;
            return obj;
        }
        public void UpdateBaseData(BaseData obj)
        {
            string strUpdate = @"update BaseData set Fun=@Fun,Status=@Status,ValueFrom=@ValueFrom,ValueTo=@ValueTo,Level=@Level,Version=@Version,Description=@Description,ParentNo=@ParentNo,DisplayOrder=@DisplayOrder where RuleNO=@RuleNO";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("RuleNO", DbType.Int32).Value = obj.RuleNO;
            p.Add("Fun", DbType.String).Value = obj.Fun;
            p.Add("Status", DbType.String).Value = obj.Status;
            p.Add("ValueFrom", DbType.String).Value = obj.ValueFrom;
            p.Add("ValueTo", DbType.String).Value = obj.ValueTo;
            p.Add("Level", DbType.String).Value = obj.Level;
            p.Add("Version", DbType.Int32).Value = obj.Version;
            p.Add("Description", DbType.String).Value = obj.Description;
            p.Add("ParentNo", DbType.Int32).Value = obj.ParentNo;
            p.Add("DisplayOrder", DbType.Int32).Value = obj.DisplayOrder;

            DBHelper.TemplateMySQL.ExecuteNonQuery(CommandType.Text, strUpdate, p);
        }
        public BaseData GetBaseData(int ruleno)
        {
            string strSel = baseBaseData + " where RuleNO=@RuleNO";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();
            p.Add("RuleNO", DbType.Int32).Value = ruleno;


            IList<BaseData> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<BaseData>(MapBaseData), p);
            return lst.Count == 0 ? null : lst[0];
        }
        public IList<BaseData> ListBaseData()
        {
            string strSel = baseBaseData;

            IList<BaseData> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<BaseData>(MapBaseData));

            return lst;
        }

        #endregion

        #region lifeCycleEvent
        private string baseLifecycleEvent = "select ID,RoleType,RoleNO,Fun,ValueFrom,ValueTo,UpdatedTime,UpdatedUser,Remark,EventID,ParentID from LifecycleEvent";
        public LifecycleEvent CreateLifecycleEvent(LifecycleEvent obj)
        {
            string strIns = @"insert into LifecycleEvent(RoleType,RoleNO,Fun,ValueFrom,ValueTo,UpdatedTime,UpdatedUser,Remark,EventID,ParentID) values(@RoleType,@RoleNO,@Fun,@ValueFrom,@ValueTo,@UpdatedTime,@UpdatedUser,@Remark,@EventID,@ParentID);SELECT LAST_INSERT_ID() as id";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("ID", DbType.Int32).Value = obj.ID;
            p.Add("EventID", DbType.Int32).Value = obj.EventID;
            p.Add("ParentID", DbType.Int32).Value = obj.ParentID;
            p.Add("RoleType", DbType.String).Value = obj.RoleType;
            p.Add("RoleNO", DbType.Int32).Value = obj.RoleNO;
            p.Add("Fun", DbType.String).Value = obj.Fun;
            p.Add("ValueFrom", DbType.String).Value = obj.ValueFrom;
            p.Add("ValueTo", DbType.String).Value = obj.ValueTo;
            p.Add("UpdatedTime", DbType.DateTime).Value = obj.UpdatedTime;
            p.Add("UpdatedUser", DbType.Int32).Value = obj.UpdatedUser;
            p.Add("Remark", DbType.String).Value = obj.Remark;

            int num = Int32.Parse(DBHelper.TemplateMySQL.ExecuteScalar(CommandType.Text, strIns, p).ToString());
            obj.ID = num;
            return obj;
        }
        public void UpdateLifecycleEvent(LifecycleEvent obj)
        {
            string strUpdate = @"update LifecycleEvent set RoleType=@RoleType,RoleNO=@RoleNO,Fun=@Fun,ValueFrom=@ValueFrom,ValueTo=@ValueTo,UpdatedTime=@UpdatedTime,UpdatedUser=@UpdatedUser,Remark=@Remark where ID=@ID";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("ID", DbType.Int32).Value = obj.ID;
            p.Add("RoleType", DbType.String).Value = obj.RoleType;
            p.Add("RoleNO", DbType.Int32).Value = obj.RoleNO;
            p.Add("Fun", DbType.String).Value = obj.Fun;
            p.Add("ValueFrom", DbType.String).Value = obj.ValueFrom;
            p.Add("ValueTo", DbType.String).Value = obj.ValueTo;
            p.Add("UpdatedTime", DbType.DateTime).Value = obj.UpdatedTime;
            p.Add("UpdatedUser", DbType.Int32).Value = obj.UpdatedUser;
            p.Add("Remark", DbType.String).Value = obj.Remark;

            DBHelper.TemplateMySQL.ExecuteNonQuery(CommandType.Text, strUpdate, p);
        }
        public LifecycleEvent GetLifecycleEvent(int id)
        {
            string strSel = baseLifecycleEvent + " where ID=@ID";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();
            p.Add("ID", DbType.Int32).Value = id;


            IList<LifecycleEvent> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<LifecycleEvent>(MapLifecycleEvent), p);
            return lst.Count == 0 ? null : lst[0];
        }
        public IList<LifecycleEvent> ListLifecycleEvent()
        {
            string strSel = baseLifecycleEvent;

            IList<LifecycleEvent> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<LifecycleEvent>(MapLifecycleEvent));

            return lst;
        }

        #endregion

        #region fileSystem
        private string baseFileSystem = "select FileNO,Fun,TypeName,InstanceID,Path,Status,CtreateTime,OldName,NewName,CreateUser,BelongNO from FileSystem";
        public FileSystem CreateFileSystem(FileSystem obj)
        {
            string strIns = @"insert into FileSystem(Fun,TypeName,InstanceID,Path,Status,CtreateTime,OldName,NewName,CreateUser,BelongNO) values(@Fun,@TypeName,@InstanceID,@Path,@Status,@CtreateTime,@OldName,@NewName,@CreateUser,@BelongNO);SELECT LAST_INSERT_ID() as id";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("FileNO", DbType.Int32).Value = obj.FileNO;
            p.Add("Fun", DbType.String).Value = obj.Fun;
            p.Add("TypeName", DbType.String).Value = obj.TypeName;
            p.Add("InstanceID", DbType.String).Value = obj.InstanceID;
            p.Add("Path", DbType.String).Value = obj.Path;
            p.Add("Status", DbType.String).Value = obj.Status;
            p.Add("CtreateTime", DbType.DateTime).Value = obj.CtreateTime;
            p.Add("OldName", DbType.String).Value = obj.OldName;
            p.Add("NewName", DbType.String).Value = obj.NewName;
            p.Add("CreateUser", DbType.Int32).Value = obj.CreateUser;
            p.Add("BelongNO", DbType.Int32).Value = obj.BelongNO;

            int num = Int32.Parse(DBHelper.TemplateMySQL.ExecuteScalar(CommandType.Text, strIns, p).ToString());
            obj.FileNO = num;
            return obj;
        }
        public void UpdateFileSystem(FileSystem obj)
        {
            string strUpdate = @"update FileSystem set Fun=@Fun,TypeName=@TypeName,InstanceID=@InstanceID,Path=@Path,Status=@Status,CtreateTime=@CtreateTime,OldName=@OldName,NewName=@NewName,CreateUser=@CreateUser,BelongNO=@BelongNO where FileNO=@FileNO";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("FileNO", DbType.Int32).Value = obj.FileNO;
            p.Add("Fun", DbType.String).Value = obj.Fun;
            p.Add("TypeName", DbType.String).Value = obj.TypeName;
            p.Add("InstanceID", DbType.String).Value = obj.InstanceID;
            p.Add("Path", DbType.String).Value = obj.Path;
            p.Add("Status", DbType.String).Value = obj.Status;
            p.Add("CtreateTime", DbType.DateTime).Value = obj.CtreateTime;
            p.Add("OldName", DbType.String).Value = obj.OldName;
            p.Add("NewName", DbType.String).Value = obj.NewName;
            p.Add("CreateUser", DbType.Int32).Value = obj.CreateUser;
            p.Add("BelongNO", DbType.Int32).Value = obj.BelongNO;

            DBHelper.TemplateMySQL.ExecuteNonQuery(CommandType.Text, strUpdate, p);
        }
        public FileSystem GetFileSystem(int fileno)
        {
            string strSel = baseFileSystem + " where FileNO=@FileNO";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();
            p.Add("FileNO", DbType.Int32).Value = fileno;


            IList<FileSystem> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<FileSystem>(MapFileSystem), p);
            return lst.Count == 0 ? null : lst[0];
        }
        public IList<FileSystem> ListFileSystem()
        {
            string strSel = baseFileSystem;

            IList<FileSystem> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<FileSystem>(MapFileSystem));

            return lst;
        }

        public IList<FileSystem> ListFileSystem(FileType type, int belongno)
        {
            string strSel = baseFileSystem + " where  belongno=@belongno";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("belongno", DbType.Int32).Value = belongno;
            if (type != FileType.All)
            {
                strSel += " and fun=@type";
                p.Add("type", DbType.String).Value = type;

            }

            IList<FileSystem> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<FileSystem>(MapFileSystem), p);
            return lst;
        }


        #endregion

        #region seldomUsed
        private string baseSeldomUsed = "select ID,BelongNo,BelongType,Type,Value,Status from SeldomUsed";
        public SeldomUsed CreateSeldomUsed(SeldomUsed obj)
        {
            string strIns = @"insert into SeldomUsed(BelongNo,BelongType,Type,Value,Status) values(@BelongNo,@BelongType,@Type,@Value,@Status);SELECT LAST_INSERT_ID() as id";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("ID", DbType.Int32).Value = obj.ID;
            p.Add("BelongNo", DbType.Int32).Value = obj.BelongNo;
            p.Add("BelongType", DbType.String).Value = obj.BelongType;
            p.Add("Type", DbType.String).Value = obj.Type;
            p.Add("Value", DbType.String).Value = obj.Value;
            p.Add("Status", DbType.String).Value = obj.Status;

            int num = Int32.Parse(DBHelper.TemplateMySQL.ExecuteScalar(CommandType.Text, strIns, p).ToString());
            obj.ID = num;
            return obj;
        }

        public void UpdateSeldomUsed(SeldomUsed obj)
        {
            string strUpdate = @"update SeldomUsed set BelongNo=@BelongNo,BelongType=@BelongType,Type=@Type,Value=@Value,Status=@Status where ID=@ID";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("ID", DbType.Int32).Value = obj.ID;
            p.Add("BelongNo", DbType.Int32).Value = obj.BelongNo;
            p.Add("BelongType", DbType.String).Value = obj.BelongType;
            p.Add("Type", DbType.String).Value = obj.Type;
            p.Add("Value", DbType.String).Value = obj.Value;
            p.Add("Status", DbType.String).Value = obj.Status;

            DBHelper.TemplateMySQL.ExecuteNonQuery(CommandType.Text, strUpdate, p);
        }
        public SeldomUsed GetSeldomUsed(int id)
        {
            string strSel = baseSeldomUsed + " where ID=@ID";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();
            p.Add("ID", DbType.Int32).Value = id;


            IList<SeldomUsed> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<SeldomUsed>(MapSeldomUsed), p);
            return lst.Count == 0 ? null : lst[0];
        }

        public IList<SeldomUsed> ListSeldomUsed(int belongID, SeldomType type, APPRole role)
        {
            string strSel = baseSeldomUsed + " where BelongNo=@BelongNo And BelongType=@BelongType ";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();
            p.Add("BelongNo", DbType.Int32).Value = belongID;
            p.Add("BelongType", DbType.String).Value = role;

            if (type != SeldomType.All)
            {
                p.Add("Type", DbType.String).Value = type;
                strSel += "AND type=@Type";
            }
            IList<SeldomUsed> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<SeldomUsed>(MapSeldomUsed), p);
            return lst;
        }

        public IList<SeldomUsed> ListSeldomUsed()
        {
            string strSel = baseSeldomUsed;

            IList<SeldomUsed> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<SeldomUsed>(MapSeldomUsed));

            return lst;
        }
        #endregion

        #region relationship
        private string baseRelationship = "select ID,NOFrom,Fun,NOTo,NameFrom,Status,NameTo,CreateTime from Relationship";
        public Relationship CreateRelationship(Relationship obj)
        {
            string strIns = @"insert into Relationship(NOFrom,Fun,NOTo,NameFrom,Status,NameTo,CreateTime) values(@NOFrom,@Fun,@NOTo,@NameFrom,@Status,@NameTo,@CreateTime);SELECT LAST_INSERT_ID() as id";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("ID", DbType.Int32).Value = obj.ID;
            p.Add("NOFrom", DbType.Int32).Value = obj.NOFrom;
            p.Add("Fun", DbType.String).Value = obj.Fun;
            p.Add("NOTo", DbType.Int32).Value = obj.NOTo;
            p.Add("NameFrom", DbType.String).Value = obj.NameFrom;
            p.Add("Status", DbType.String).Value = obj.Status;
            p.Add("NameTo", DbType.String).Value = obj.NameTo;
            p.Add("CreateTime", DbType.DateTime).Value = obj.CreateTime;

            int num = Int32.Parse(DBHelper.TemplateMySQL.ExecuteScalar(CommandType.Text, strIns, p).ToString());
            obj.ID = num;
            return obj;
        }
        public void UpdateRelationship(Relationship obj)
        {
            string strUpdate = @"update Relationship set NOFrom=@NOFrom,Fun=@Fun,NOTo=@NOTo,NameFrom=@NameFrom,Status=@Status,NameTo=@NameTo,CreateTime=@CreateTime where ID=@ID";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("ID", DbType.Int32).Value = obj.ID;
            p.Add("NOFrom", DbType.Int32).Value = obj.NOFrom;
            p.Add("Fun", DbType.String).Value = obj.Fun;
            p.Add("NOTo", DbType.Int32).Value = obj.NOTo;
            p.Add("NameFrom", DbType.String).Value = obj.NameFrom;
            p.Add("Status", DbType.String).Value = obj.Status;
            p.Add("NameTo", DbType.String).Value = obj.NameTo;
            p.Add("CreateTime", DbType.DateTime).Value = obj.CreateTime;

            DBHelper.TemplateMySQL.ExecuteNonQuery(CommandType.Text, strUpdate, p);
        }

        public Relationship GetRelationship(int id)
        {
            string strSel = baseRelationship + " where ID=@ID";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();
            p.Add("ID", DbType.Int32).Value = id;


            IList<Relationship> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<Relationship>(MapRelationship), p);
            return lst.Count == 0 ? null : lst[0];
        }

        public IList<Relationship> ListRelationship()
        {
            string strSel = baseRelationship;

            IList<Relationship> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<Relationship>(MapRelationship));

            return lst;
        }
        public IList<Relationship> ListRelationship(RelationshipFun type, int toNO)
        {
            string strSel = baseRelationship + " where Fun=@Fun and NOTo=@NOTo";
            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("Fun", DbType.String).Value = type;
            p.Add("NOTo", DbType.Int32).Value = toNO;
            IList<Relationship> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<Relationship>(MapRelationship), p);

            return lst;
        }

        #endregion

        #region spliteWord
        private string baseSpliteWord = "select ID,Fun,Value,SpliteValue from SpliteWord";
        public SpliteWord CreateSpliteWord(SpliteWord obj)
        {
            string strIns = @"insert into SpliteWord(ID,Fun,Value,SpliteValue) values(@ID,@Fun,@Value,@SpliteValue);";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("ID", DbType.Int32).Value = obj.ID;
            p.Add("Fun", DbType.String).Value = obj.Fun;
            p.Add("Value", DbType.String).Value = obj.Value;
            p.Add("SpliteValue", DbType.String).Value = obj.SpliteValue;

            DBHelper.TemplateMySQL.ExecuteNonQuery(CommandType.Text, strIns, p);
            return obj;
        }
        public void UpdateSpliteWord(SpliteWord obj)
        {
            string strUpdate = @"update SpliteWord set Fun=@Fun,Value=@Value,SpliteValue=@SpliteValue where ID=@ID";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("ID", DbType.Int32).Value = obj.ID;
            p.Add("Fun", DbType.String).Value = obj.Fun;
            p.Add("Value", DbType.String).Value = obj.Value;
            p.Add("SpliteValue", DbType.String).Value = obj.SpliteValue;

            DBHelper.TemplateMySQL.ExecuteNonQuery(CommandType.Text, strUpdate, p);
        }
        public SpliteWord GetSpliteWord(int id)
        {
            string strSel = baseSpliteWord + " where ID=@ID";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();
            p.Add("ID", DbType.Int32).Value = id;


            IList<SpliteWord> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<SpliteWord>(MapSpliteWord), p);
            return lst.Count == 0 ? null : lst[0];
        }
        public IList<SpliteWord> ListSpliteWord()
        {
            string strSel = baseSpliteWord;

            IList<SpliteWord> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<SpliteWord>(MapSpliteWord));

            return lst;
        }

        public IDictionary<string, string> ListWrodToSpliteByType(SpliteWordFun fun)
        {
            string strSel = string.Empty;
            IDictionary<string, string> dic = new Dictionary<string, string>();
            switch (fun)
            {
                case SpliteWordFun.School:
                    strSel = "select SchoolNO, SchoolName from school where SchoolNO not in(select ID from spliteword where Fun='School')";
                    break;
                case SpliteWordFun.Association:
                    strSel = "select AssociationNO, Name from association where AssociationNO not in(select ID from spliteword where Fun='Association')";
                    break;
            }

            DBHelper.TemplateMySQL.QueryWithRowCallbackDelegate(CommandType.Text, strSel, (dr) =>
            {
                string key = dr.GetString(0);
                string value = dr.GetString(1);

                if (!key.IsNullOrEmpty() && !value.IsNullOrEmpty() && !dic.ContainsKey(key))
                    dic.Add(key, value);
            });

            return dic;
        }

        #endregion

        #region validation
        private string baseValidation = "select ID,Fun,ValidateNO,ValidateName,ValidStatus,ValueFrom,ValueTo,CreatedTime,UpdatedTime from Validation";
        public Validation CreateValidation(Validation obj)
        {
            string strIns = @"insert into Validation(Fun,ValidateNO,ValidateName,ValidStatus,ValueFrom,ValueTo,CreatedTime,UpdatedTime) values(@Fun,@ValidateNO,@ValidateName,@ValidStatus,@ValueFrom,@ValueTo,@CreatedTime,@UpdatedTime);SELECT LAST_INSERT_ID() as id";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("ID", DbType.Int32).Value = obj.ID;
            p.Add("Fun", DbType.String).Value = obj.Fun;
            p.Add("ValidateNO", DbType.Int32).Value = obj.ValidateNO;
            p.Add("ValidateName", DbType.String).Value = obj.ValidateName;
            p.Add("ValidStatus", DbType.String).Value = obj.ValidStatus;
            p.Add("ValueFrom", DbType.String).Value = obj.ValueFrom;
            p.Add("ValueTo", DbType.String).Value = obj.ValueTo;
            p.Add("CreatedTime", DbType.DateTime).Value = obj.CreatedTime;
            p.Add("UpdatedTime", DbType.DateTime).Value = obj.UpdatedTime;

            int num = Int32.Parse(DBHelper.TemplateMySQL.ExecuteScalar(CommandType.Text, strIns, p).ToString());
            obj.ID = num;
            return obj;
        }
        public void UpdateValidation(Validation obj)
        {
            string strUpdate = @"update Validation set Fun=@Fun,ValidateNO=@ValidateNO,ValidateName=@ValidateName,ValidStatus=@ValidStatus,ValueFrom=@ValueFrom,ValueTo=@ValueTo,CreatedTime=@CreatedTime,UpdatedTime=@UpdatedTime where ID=@ID";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("ID", DbType.Int32).Value = obj.ID;
            p.Add("Fun", DbType.String).Value = obj.Fun;
            p.Add("ValidateNO", DbType.Int32).Value = obj.ValidateNO;
            p.Add("ValidateName", DbType.String).Value = obj.ValidateName;
            p.Add("ValidStatus", DbType.String).Value = obj.ValidStatus;
            p.Add("ValueFrom", DbType.String).Value = obj.ValueFrom;
            p.Add("ValueTo", DbType.String).Value = obj.ValueTo;
            p.Add("CreatedTime", DbType.DateTime).Value = obj.CreatedTime;
            p.Add("UpdatedTime", DbType.DateTime).Value = obj.UpdatedTime;

            DBHelper.TemplateMySQL.ExecuteNonQuery(CommandType.Text, strUpdate, p);
        }
        public Validation GetValidation(int id)
        {
            string strSel = baseValidation + " where ID=@ID";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();
            p.Add("ID", DbType.Int32).Value = id;


            IList<Validation> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<Validation>(MapValidation), p);
            return lst.Count == 0 ? null : lst[0];
        }
        public IList<Validation> ListValidation()
        {
            string strSel = baseValidation;

            IList<Validation> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSel, new RowMapperDelegate<Validation>(MapValidation));

            return lst;
        }

        #endregion

        #region UserMessage

        private string baseUserMessage = "select ID,MessageType,Sender,Receiver,Content,SendType,SendTime,ReadTime,Status from UserMessage";
        public void CreateUserMessage(UserMessage obj)
        {
            string strIns = @"insert into UserMessage(MessageType,Sender,Receiver,Content,SendType,SendTime,ReadTime,Status) values(@MessageType,@Sender,@Receiver,@Content,@SendType,@SendTime,@ReadTime,@Status)";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("MessageType", DbType.String).Value = obj.MessageType;
            p.Add("Sender", DbType.String).Value = obj.Sender;
            p.Add("Receiver", DbType.String).Value = obj.Receiver;
            p.Add("Content", DbType.String).Value = obj.Content;
            p.Add("SendType", DbType.String).Value = obj.SendType.ToString();
            p.Add("SendTime", DbType.DateTime).Value = DateTime.Now;
            p.Add("ReadTime", DbType.DateTime).Value = DateTime.Now;
            p.Add("Status", DbType.String).Value = obj.Status.ToString();

            DBHelper.TemplateMySQL.ExecuteNonQuery(CommandType.Text, strIns, p);
        }

        public void UpdateUserMessage(UserMessage obj)
        {
            string strUpdate = @"update UserMessage set ReadTime=@ReadTime,Status=@Status where ID=@ID";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();
            p.Add("ID", DbType.Int32).Value = obj.ID;
            p.Add("ReadTime", DbType.DateTime).Value = obj.ReadTime;
            p.Add("Status", DbType.String).Value = obj.Status;

            DBHelper.TemplateMySQL.ExecuteNonQuery(CommandType.Text, strUpdate, p);
        }

        public UserMessage GetUserMessage(int id)
        {
            string strSql = baseUserMessage + " where ID=@ID";

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();

            p.Add("ID", DbType.String).Value = id;

            IList<UserMessage> lst = DBHelper.TemplateMySQL.QueryWithRowMapperDelegate(CommandType.Text, strSql, new RowMapperDelegate<UserMessage>(MapUserMessage), p);
            return lst.Count == 0 ? null : lst[0];
        }

        public JObject ListUserMessage(string userNo, int start, int limit)
        {
            string strSql = "select sql_calc_found_rows ID,MessageType,Sender,Receiver,Content,SendType,SendTime,ReadTime,Status "
                + "from UserMessage where Receiver=@Receiver and Status=@Status limit @start,@limit;select found_rows()";

            start = start == 0 ? 1 : start;
            limit = limit == 0 ? 10 : limit;

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();
            p.Add("Receiver", DbType.String).Value = userNo;
            p.Add("Status", DbType.String).Value = CommonStatus.Pending;
            p.Add("start", DbType.Int32).Value = (start - 1) * limit;
            p.Add("limit", DbType.Int32).Value = limit;

            return QueryHelper.QueryPagingJson(strSql, p);
        }

        #endregion

        #region Eventlog

        public JObject ListEventLog(IDictionary<SearchKey, string> dicCondition, int start, int limit)
        {
            StringBuilder sb = new StringBuilder();
            string strCondition = string.Empty;
            start = start == 0 ? 1 : start;
            limit = limit == 0 ? 10 : limit;

            IDbParameters p = DBHelper.TemplateMySQL.CreateDbParameters();
            p.Add("start", DbType.Int32).Value = (start - 1) * limit;
            p.Add("limit", DbType.Int32).Value = limit;

            foreach (var item in dicCondition)
            {
                switch (item.Key)
                {
                    case SearchKey.StartDate:
                        if (!item.Value.IsNullOrEmpty())
                        {
                            strCondition += " and ActionTime >= @StartDate";
                            p.Add("StartDate", DbType.String).Value = item.Value;
                        }
                        break;
                    case SearchKey.EndDate:
                        if (!item.Value.IsNullOrEmpty())
                        {
                            strCondition += " and ActionTime <= @EndDate";
                            p.Add("EndDate", DbType.String).Value = item.Value;
                        }
                        break;
                    case SearchKey.Operator:
                        if (!item.Value.IsNullOrEmpty())
                        {
                            strCondition += " and Operator = @Operator";
                            p.Add("Operator", DbType.String).Value = item.Value;
                        }
                        break;
                    case SearchKey.EventType:

                        if (!item.Value.IsNullOrEmpty())
                        {
                            strCondition += " and ActionType = @ActionType";
                            p.Add("ActionType", DbType.String).Value = item.Value;
                        }

                        break;
                    case SearchKey.EventObject:

                        if (!item.Value.IsNullOrEmpty())
                        {
                            strCondition += " and ActionObject = @ActionObject";
                            p.Add("ActionObject", DbType.String).Value = item.Value;
                        }

                        break;
                    case SearchKey.EventID:
                        if (!item.Value.IsNullOrEmpty())
                        {
                            strCondition += " and EventID = @EventID";
                            p.Add("EventID", DbType.String).Value = item.Value;
                        }
                        break;
                }
            }

            string strSql = "select sql_calc_found_rows ID,EventID,ActionType,ActionObject,ActionTime,Operator,Remark from eventlog where 1=1"
                + strCondition + " order by ActionTime desc limit @start,@limit;select found_rows()";

            return QueryHelper.QueryPagingJson(strSql, p);
        }

        #endregion

        #region Map
        private School MapSchool(IDataReader dr, int count)
        {
            School obj = new School();
            obj.SchoolNO = dr.GetInt32(0);
            obj.SchoolName = dr.IsDBNull(1) ? String.Empty : dr.GetString(1);
            obj.StudentSize = dr.IsDBNull(2) ? 0 : dr.GetInt32(2);
            obj.ProvinceNO = dr.IsDBNull(3) ? 0 : dr.GetInt32(3);
            obj.CityNO = dr.IsDBNull(4) ? 0 : dr.GetInt32(4);
            obj.CountyNO = dr.IsDBNull(5) ? 0 : dr.GetInt32(5);
            obj.Address = dr.IsDBNull(6) ? String.Empty : dr.GetString(6);

            return obj;
        }
        private EventLog MapEventLog(IDataReader dr, int count)
        {
            EventLog obj = new EventLog();
            obj.ID = dr.GetInt32(0);
            obj.InstanceID = dr.IsDBNull(1) ? String.Empty : dr.GetString(1);
            obj.EventID = dr.IsDBNull(2) ? String.Empty : dr.GetString(2);
            obj.ActionType = (EventType)Enum.Parse(typeof(EventType), dr.GetString(3), true);
            obj.ActionObject = dr.IsDBNull(4) ? String.Empty : dr.GetString(4);
            obj.ActionTime = dr.GetDateTime(5);
            obj.Operator = dr.IsDBNull(6) ? String.Empty : dr.GetString(6);
            obj.Remark = dr.IsDBNull(7) ? String.Empty : dr.GetString(7);

            return obj;
        }


        private Relationship MapRelationship(IDataReader dr, int count)
        {
            Relationship obj = new Relationship();
            obj.ID = dr.GetInt32(0);
            obj.NOFrom = dr.GetInt32(1);
            obj.Fun = (RelationshipFun)Enum.Parse(typeof(RelationshipFun), dr.GetString(2), true);
            obj.NOTo = dr.GetInt32(3);
            obj.NameFrom = dr.IsDBNull(4) ? String.Empty : dr.GetString(4);
            obj.Status = (CommonStatus)Enum.Parse(typeof(CommonStatus), dr.GetString(5), true);
            obj.NameTo = dr.IsDBNull(6) ? String.Empty : dr.GetString(6);
            obj.CreateTime = dr.GetDateTime(7);

            return obj;
        }
        private LifecycleEvent MapLifecycleEvent(IDataReader dr, int count)
        {
            LifecycleEvent obj = new LifecycleEvent();
            obj.ID = dr.GetInt32(0);
            obj.RoleType = (APPRole)Enum.Parse(typeof(APPRole), dr.GetString(1), true);
            obj.RoleNO = dr.GetInt32(2);
            obj.Fun = (LifeCycleFun)Enum.Parse(typeof(LifeCycleFun), dr.GetString(3), true);
            obj.ValueFrom = dr.IsDBNull(4) ? String.Empty : dr.GetString(4);
            obj.ValueTo = dr.IsDBNull(5) ? String.Empty : dr.GetString(5);
            obj.UpdatedTime = dr.GetDateTime(6);
            obj.UpdatedUser = dr.GetInt32(7);
            obj.Remark = dr.IsDBNull(8) ? String.Empty : dr.GetString(8);
            obj.EventID = dr.GetInt32(9);
            obj.ParentID = dr.GetInt32(10);

            return obj;
        }
        private FileSystem MapFileSystem(IDataReader dr, int count)
        {
            FileSystem obj = new FileSystem();
            obj.FileNO = dr.GetInt32(0);
            obj.Fun = (FileType)Enum.Parse(typeof(FileType), dr.GetString(1), true);
            obj.TypeName = (APPRole)Enum.Parse(typeof(APPRole), dr.GetString(2), true);
            obj.InstanceID = dr.IsDBNull(3) ? String.Empty : dr.GetString(3);
            obj.Path = dr.IsDBNull(4) ? String.Empty : dr.GetString(4).IsNullOrEmpty() ? String.Empty : SystemConfig.Get("UploadHttpPath") + dr.GetString(4);
            obj.Status = (CommonStatus)Enum.Parse(typeof(CommonStatus), dr.GetString(5), true);
            obj.CtreateTime = dr.GetDateTime(6);
            obj.OldName = dr.IsDBNull(7) ? String.Empty : dr.GetString(7);
            obj.NewName = dr.IsDBNull(8) ? String.Empty : dr.GetString(8);
            obj.CreateUser = dr.GetInt32(9);
            obj.BelongNO = dr.GetInt32(10);

            return obj;
        }


        private BaseData MapBaseData(IDataReader dr, int count)
        {
            BaseData obj = new BaseData();
            obj.RuleNO = dr.GetInt32(0);
            obj.Fun = (BaseDataFun)Enum.Parse(typeof(BaseDataFun), dr.GetString(1), true);
            obj.Status = (CommonStatus)Enum.Parse(typeof(CommonStatus), dr.GetString(2), true);
            obj.ValueFrom = dr.IsDBNull(3) ? String.Empty : dr.GetString(3);
            obj.ValueTo = dr.IsDBNull(4) ? String.Empty : dr.GetString(4);
            obj.Level = dr.IsDBNull(5) ? String.Empty : dr.GetString(5);
            obj.Version = dr.IsDBNull(6) ? 0 : dr.GetInt32(6);
            obj.Description = dr.IsDBNull(7) ? String.Empty : dr.GetString(7);
            obj.ParentNo = dr.IsDBNull(8) ? 0 : dr.GetInt32(8);
            obj.DisplayOrder = dr.IsDBNull(9) ? 0 : dr.GetInt32(9);

            return obj;
        }
        private Money MapMoney(IDataReader dr, int count)
        {
            Money obj = new Money();
            obj.RoleNO = dr.GetInt32(0);
            obj.Fun = (APPRole)Enum.Parse(typeof(APPRole), dr.GetString(1), true);
            obj.CountMoney = dr.GetDouble(2);
            obj.Balance = dr.GetDouble(3);

            return obj;
        }
        private MoneyLog MapMoneyLog(IDataReader dr, int count)
        {
            MoneyLog obj = new MoneyLog();
            obj.ID = dr.IsDBNull(0) ? String.Empty : dr.GetString(0);
            obj.Type = (MoneyLogType)Enum.Parse(typeof(MoneyLogType), dr.GetString(1), true);
            obj.ValueFrom = dr.IsDBNull(2) ? String.Empty : dr.GetString(2);
            obj.ValueTo = dr.IsDBNull(3) ? String.Empty : dr.GetString(3);
            obj.Amount = dr.GetDouble(4);
            obj.Status = (CommonStatus)Enum.Parse(typeof(CommonStatus), dr.GetString(5), true);
            obj.CreateTime = dr.GetDateTime(6);
            obj.UpdateTime = dr.GetDateTime(7);

            return obj;
        }
        private SpliteWord MapSpliteWord(IDataReader dr, int count)
        {
            SpliteWord obj = new SpliteWord();
            obj.ID = dr.GetInt32(0);
            obj.Fun = (SpliteWordFun)Enum.Parse(typeof(SpliteWordFun), dr.GetString(1), true);
            obj.Value = dr.IsDBNull(2) ? String.Empty : dr.GetString(2);
            obj.SpliteValue = dr.IsDBNull(3) ? String.Empty : dr.GetString(3);

            return obj;
        }
        private SeldomUsed MapSeldomUsed(IDataReader dr, int count)
        {
            SeldomUsed obj = new SeldomUsed();
            obj.ID = dr.GetInt32(0);
            obj.BelongNo = dr.GetInt32(1);
            obj.BelongType = (APPRole)Enum.Parse(typeof(APPRole), dr.GetString(2), true);
            obj.Type = (SeldomType)Enum.Parse(typeof(SeldomType), dr.GetString(3), true);
            obj.Value = dr.IsDBNull(4) ? String.Empty : dr.GetString(4);
            obj.Status = (CommonStatus)Enum.Parse(typeof(CommonStatus), dr.GetString(5), true);

            return obj;
        }
        private Validation MapValidation(IDataReader dr, int count)
        {
            Validation obj = new Validation();
            obj.ID = dr.GetInt32(0);
            obj.Fun = (ValidationFun)Enum.Parse(typeof(ValidationFun), dr.GetString(1), true);
            obj.ValidateNO = dr.GetInt32(2);
            obj.ValidateName = dr.IsDBNull(3) ? String.Empty : dr.GetString(3);
            obj.ValidStatus = (CommonStatus)Enum.Parse(typeof(CommonStatus), dr.GetString(4), true);
            obj.ValueFrom = dr.IsDBNull(5) ? String.Empty : dr.GetString(5);
            obj.ValueTo = dr.IsDBNull(6) ? String.Empty : dr.GetString(6);
            obj.CreatedTime = dr.GetDateTime(7);
            obj.UpdatedTime = dr.GetDateTime(8);

            return obj;
        }
        private Area MapArea(IDataReader dr, int count)
        {
            Area obj = new Area();
            obj.Code = dr.GetInt32(0);
            obj.Name = dr.IsDBNull(1) ? String.Empty : dr.GetString(1);
            obj.Fun = (AreaFun)Enum.Parse(typeof(AreaFun), dr.GetString(2), true);
            obj.Parent = dr.IsDBNull(3) ? 0 : dr.GetInt32(3);

            return obj;
        }

        private UserMessage MapUserMessage(IDataReader dr, int count)
        {
            UserMessage obj = new UserMessage();
            obj.ID = dr.GetInt32(0);
            obj.MessageType = (UserMessageType)Enum.Parse(typeof(UserMessageType), dr.GetString(1), true);
            obj.Sender = dr.IsDBNull(1) ? String.Empty : dr.GetString(2);
            obj.Receiver = dr.IsDBNull(1) ? String.Empty : dr.GetString(3);
            obj.Content = dr.IsDBNull(1) ? String.Empty : dr.GetString(4);
            obj.SendType = (AccountType)Enum.Parse(typeof(AccountType), dr.GetString(5), true);
            obj.SendTime = dr.GetDateTime(6);
            obj.ReadTime = dr.GetDateTime(7);
            obj.Status = (CommonStatus)Enum.Parse(typeof(CommonStatus), dr.GetString(8), true);

            return obj;
        }

        #endregion
    }
}
